package cn.iocoder.yudao.module.javainfo.dal.mysql.pet;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.javainfo.controller.admin.pet.vo.PetPageReqVO;
import cn.iocoder.yudao.module.javainfo.dal.dataobject.pet.PetDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 宠物 Mapper
 *
 * @author 爪哇国大BOSS
 */
@Mapper
public interface PetMapper extends BaseMapperX<PetDO> {

    default PageResult<PetDO> selectPage(PetPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PetDO>()
                .likeIfPresent(PetDO::getPetName, reqVO.getPetName())
                .eqIfPresent(PetDO::getOwnerUserId, reqVO.getOwnerUserId())
                .betweenIfPresent(PetDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(PetDO::getId));
    }

    /**
     * 查询指定用户ID下的未删除宠物数量
     *
     * @param userId 用户ID
     * @return 宠物数量
     */
    default Long selectCountByUserId(Long userId) {
        return selectCount(new LambdaQueryWrapperX<PetDO>()
                .eq(PetDO::getOwnerUserId, userId));
    }

}